//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    sendTime: '获取验证码',
    sendColor: '#FF2823',
    snsMsgWait: 60,
    code: '123456',
    tel: '18800001100',
    avatarUrl:'/images/avatar.png',
    myName:'扬帆远航の心',
    roll_list:[
      {pic:'/images/img2.png'}
    ]
  },
  onShow(){
    let studentOpt = wx.getStorageSync('studentOpt');
    this.getStudentInfo(studentOpt.id)
  },
  // 获取学生信息
  getStudentInfo(id) {
    wx.showLoading({
      title: '数据加载中',
    })
    app._post_form('/blade-api/detail', {id}, (res) => {
      let studentInfo = res.data
      studentInfo.birthday=studentInfo.birthday.substr(0,10)
      this.setData({studentInfo})
      wx.hideLoading()
    })
  },
  copyHandle(){
    wx.setClipboardData({
      data: this.data.studentInfo.studentNo,
      success: function (res) {
        app.showMsg('复制成功')
      }
    })
  },
  getMyInfo(e){
    let info=e.detail.userInfo
    this.setData({
      myName:info.nickName,
      avatarUrl:info.avatarUrl
    })
  },
  logoutHandle(){
    app.alert({
      title:'提示',
      content:'确定退出此账号吗？',
      showCancel:true,
      cb_confirm:()=>{
        wx.redirectTo({
          url:'/pages/login/login',
          success:()=>{
            try {
              wx.clearStorageSync()
            } catch(e) {
              // Do something when catch error
              app.showMsg('清除缓存失败，请升级微信或重新登录。')
            }
          }
        })
      },
      cb_cancel:()=>{console.log('取消')}
    })
  }
})
